import request from '@/utils/request.ts';
import type { SkuAllListResData, SkuDetailResData } from './type.ts';
import type { ResponseData } from '../type.ts';

enum API {
  GET_SKU_LIST = '/admin/product/list',
  ONSALE_SKU = '/admin/product/onSale',
  CANCELSALE_SKU = '/admin/product/cancelSale',
  GET_SKU_DETAIL = '/admin/product/getSkuInfo',
  DELETE_SKU = '/admin/product/deleteSku'
}

// 获取sku列表
export const reqGetSkuList = (page: number, limit: number) =>
  request.get<any, SkuAllListResData>(`${API.GET_SKU_LIST}/${page}/${limit}`);

// 上架下架sku
export const reqToggleSkuSale = (skuId: number, onSale: boolean) => {
  const url = onSale ? API.ONSALE_SKU : API.CANCELSALE_SKU;
  return request.get<any, ResponseData>(`${url}/${skuId}`);
};

// 获取sku详情
export const reqGetSkuDetail = (skuId: number) =>
  request.get<any, SkuDetailResData>(`${API.GET_SKU_DETAIL}/${skuId}`);

// 删除sku
export const reqDeleteSku = (skuId: number) =>
  request.delete<any, ResponseData>(`${API.DELETE_SKU}/${skuId}`);
